package com.itheima.edu.manager1.dao;

import com.itheima.edu.manager1.domain.Teacher;

public class TeacherDao {
    //创建长度为5的数组用来作为数据仓库进行接收
   private static Teacher[] teachers = new Teacher[5];
    public boolean addTeacher(Teacher teacher) {

        //使用标记位思想
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            //将接受的老师对对象添加到数组中,对数组进行遍历将添加的对象加入到null索引位置
            Teacher teacher1 = teachers[i];
            //判断是否为null,若有一个是null立即赋值给index
            if(teacher1 == null){
                index = i;
                break;
            }
        }
        if(index == -1){
            return false;
        }else{
            //把传过来的teacher对象赋值给index索引位置的teachers[]数组
            teachers[index]=teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }
}
